//
//  binarySearchTreeSet.swift
//  SetAndMap
//
//  Created by lhc on 2024/7/20.
//

import Foundation


class BinarySearchTreeSet<E: Comparable>: MySet {
    private let bst = BinarySearchTree<E>()
    
    func getSize() -> Int {
        return self.bst.getSize()
    }
    
    func isEmpty() -> Bool {
        return self.bst.isEmpty()
    }
    
    func add(element: E) {
        self.bst.add(e: element)
    }
    
    func contains(_ element: E) -> Bool {
        return self.bst.containsElement(element)
    }
    
    func removeElement(_ element: E) {
        try? self.bst.removeElement(element)
    }
}


extension BinarySearchTreeSet: CustomStringConvertible {
    var description: String {
        var elementArray = [E]()
        self.bst.levelOrder { e in
            if let e = e {
                elementArray.append(e)
            }
        }
        return "\(elementArray)"
    }
    
    
}

